package com.wenan.data
{
	import com.adobe.serialization.json.JSON;
	
	import mx.formatters.DateFormatter;

	public class DataUtil
	{
		public function DataUtil()
		{
		}
		
		/**
		 * Flex对象转Json字符串。
		 */
		public static function objectToJson(obj:Object):String
		{
			return JSON.encode(obj);
		}
		
		/**
		 * Json字符串转Flex对象。
		 */
		public static function jsonToObject(json:String):Object
		{
			return JSON.decode(json);
		}
		
		public static function formatDate(date:Date):String
		{
			var dataFormatter:mx.formatters.DateFormatter = new mx.formatters.DateFormatter();
			dataFormatter.formatString = "YYYY-MM-DD";
			if (date == null)
			{
				return "";
			}
			return dataFormatter.format(date);
		}
		
		public static function getFileName(positionType:int):String
		{
			switch(positionType)
			{
				case PositionType.SQUARE:
					return "Org";
				case PositionType.FLOOR:
					return "Floor";
				case PositionType.SHOP:
					return "Shop";
				case PositionType.MAINSHOP:
					return "MainShop";
				default:
					return "";
			}
		}
		
		public static function getPostionType(fileName:String):int
		{
			switch(fileName)
			{
				case "Org":
					return PositionType.SQUARE;
				case "Floor":
					return PositionType.FLOOR;
				case "Shop":
					return PositionType.SHOP;
				case "MainShop":
					return PositionType.MAINSHOP;
				default:
					return PositionType.GLOBAL;			
			}
		}
		
		public static function formatPageName(name:String):String
		{
			switch (name){
				case "table":
					return "表格";
				case "column":
					return "柱状图";
				case "line":
					return "线状图";
				case "cluster":
					return "簇状图";
				case "scatter":
					return "散点图";
				default:
					return null;
			}
		}
		
		public static function convertColor(color:String):uint 
		{
			color = color.replace("#", "0x");
			return uint(color);
		}
		
		public static function pageNameCheck(pageName:String):Boolean
		{
			if (pageName == "CountryNavigator" ||
				pageName == "SquareHomePage" ||
				pageName == "ShopHomePage" ||
				pageName == "MainShopHomePage")
			{
				return true;
			} else 
			{
				return false;
			}
		}
	}
}